<?php


namespace app\admin\controller;


use app\admin\model\Admin as AdminModel;
use app\common\controller\AdminController;
use think\Exception;
use think\facade\Request;

class Login extends AdminController {

    public $notNeedToken = ['checklogin'];

    protected $notNeedAuthAction = ['quit'];

    public function checkLogin() {
        try {
            if (Request::isPost()) {
                $params = $this->checkParams('account,pwd');
                if ($params === false) return $this->resErr();
                $res = AdminModel::checkLogin($params);
                if (!$res) return $this->resErr();
                else return $this->resData('success', $res);
            }
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 退出登录
     * @return false|string
     */
    public function quit(){
        try {
            $params = $this->checkParams('');
            if ($params === false) return $this->resErr();
            $res = AdminModel::quit($this->headers,$this->uInfo);
            if (!$res) return $this->resErr();
            else return $this->resData('退出成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

}